<!--
 * @Author: lilin_:）
 * @version: 1.0
 * @Descripttion: 出纳明细
 * @Date: 2021-08-27 09:09:37
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-03-30 11:41:00
-->
<template>
	<div class="system-user-container">
		<el-card class="box-card">
			<div>
				<div class="my_btn_lay">
					<div class="my_flex my_btn" @click="searchEvent">
						<div class="my_flex_layout">
							<i class="vxe-icon--search"></i>
							<span>查找</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="resetEvent">
						<div class="my_flex_layout">
							<i class="vxe-icon--refresh"></i>
							<span>重置</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="addDefaultBlank">
						<div class="my_flex_layout">
							<i class="vxe-icon--plus"></i>
							<span>新增</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="deleteTable">
						<div class="my_flex_layout">
							<i class="fa fa-trash-o"></i>
							<span>删除</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="uploadingbutton_chula">
						<div class="my_flex_layout">
							<i class="vxe-icon--upload"></i>
							<span>导入</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="funnelEvent">
						<div class="my_flex_layout">
							<i class="vxe-icon--download"></i>
							<span>导出</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="printTab">
						<div class="my_flex_layout">
							<i class="vxe-icon--print"></i>
							<span>打印</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="getBankData_button">
						<div class="my_flex_layout">
							<i class="el-icon-folder-opened"></i>
							<span>银行数据</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="addUnit">
						<div class="my_flex_layout">
							<i class="el-icon-folder-opened"></i>
							<span>添加单位</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="showAmendFun">
						<div class="my_flex_layout">
							<i class="el-icon-edit"></i>
							<span>编辑</span>
						</div>
					</div>
					<div class="my_flex my_btn ml20" @click="editClosedEvent">
						<div class="my_flex_layout">
							<i class="el-icon-folder-add"></i>
							<span>保存</span>
						</div>
					</div>
				</div>

				<vxe-form :data="selectFrom" title-align="left" prevent-submit title-colon>
					<vxe-form-item title="银行" field="bankId" span="6" :item-render="{}">
						<template #default="{ data }">
							<el-select style="width: 100%" clearable filterable v-model="data.bankId" placeholder="请选择银行">
								<el-option v-for="item in bankFrom.shoWData" :key="item.id" :label="item.bank" :value="item.id"> </el-option>
							</el-select>
						</template>
					</vxe-form-item>

					<vxe-form-item title="到款单位" field="receiveId" span="6" :item-render="{}">
						<template #default="{ data }">
							<el-select style="width: 100%" clearable filterable v-model="data.receiveId" placeholder="请选择到款单位">
								<el-option v-for="item in selectFrom.bankData" :key="item.id" :label="item.unitName" :value="item.id"> </el-option>
							</el-select>
						</template>
					</vxe-form-item>

					<vxe-form-item title="去款单位" field="toId" span="6" :item-render="{}">
						<template #default="{ data }">
							<el-select style="width: 100%" clearable filterable v-model="data.toId" placeholder="请选择去款单位">
								<el-option v-for="item in selectFrom.debitUnit" :key="item.id" :label="item.unitName" :value="item.id"> </el-option>
							</el-select>
						</template>
					</vxe-form-item>

					<vxe-form-item title="项目" field="contractId" span="6" :item-render="{}">
						<template #default="{ data }">
							<el-select style="width: 100%" clearable filterable v-model="data.contractId" placeholder="请选择项目">
								<el-option v-for="item in selectFrom.contractData" :key="item.id" :label="item.contractName" :value="item.id"> </el-option>
							</el-select>
						</template>
					</vxe-form-item>

					<vxe-form-item title="开始时间" field="time" span="6" :item-render="{}">
						<template #default="{ data }">
							<el-date-picker value-format="YYYY-MM-DD HH:mm:ss" v-model="data.time1" type="date" placeholder="开始时间"> </el-date-picker>
						</template>
					</vxe-form-item>

					<vxe-form-item title="结束时间" field="time" span="6" :item-render="{}">
						<template #default="{ data }">
							<el-date-picker value-format="YYYY-MM-DD HH:mm:ss" v-model="data.time2" type="date" placeholder="结束日期"> </el-date-picker>
						</template>
					</vxe-form-item>

					<vxe-form-item title="用途" field="bankId" span="6" :item-render="{}">
						<template #default="{ data }">
							<el-input v-model="data.purpose" placeholder="请输入用途" clearable />
						</template>
					</vxe-form-item>

					<vxe-form-item title="备注" field="bankId" span="6" :item-render="{}">
						<template #default="{ data }">
							<el-input v-model="data.remarks" placeholder="请输入备注" clearable />
						</template>
					</vxe-form-item>

					<!-- <vxe-form-item title="时间" field="time" span="6" :item-render="{}">
						<template #default="{ data }">
							<el-date-picker
								style="width: 100%"
								v-model="data.time"
								type="datetimerange"
								range-separator="至"
								start-placeholder="开始日期"
								end-placeholder="结束日期"
								value-format="YYYY-MM-DD HH:mm:ss"
							>
							</el-date-picker>
						</template>
					</vxe-form-item> -->

					<!-- <vxe-form-item align="right" span="24" collapse-node>
						<template #default>
							<vxe-button status="primary" content="搜索" @click="searchEvent"></vxe-button>
							<vxe-button content="重置" @click="resetEvent"></vxe-button>
						</template>
					</vxe-form-item> -->
				</vxe-form>
			</div>

			<!-- <vxe-toolbar ref="xToolbar" custom>
				<template #buttons>
					<vxe-button type="text" icon="fa fa-plus" content="新增" @click="addDefaultBlank"></vxe-button>
					<vxe-button type="text" icon="fa fa-trash-o" content="删除" @click="deleteTable"></vxe-button>
					<vxe-button type="text" icon="fa fa-plus" content="新增银行" @click="getBankData_button"></vxe-button>
				</template>
				<template #tools>
					<vxe-button type="text" icon="vxe-icon--print" class="tool-btn" @click="printTab"></vxe-button>
					<vxe-button type="text" icon="vxe-icon--download" class="tool-btn" @click="funnelEvent"></vxe-button>
				</template>
			</vxe-toolbar> -->
			<!-- @edit-closed="editClosedEvent" -->
			<vxe-table
				:scroll-x="{ enabled: false }"
				:scroll-y="{ enabled: false }"
				align="center"
				class="mytable-style"
				:row-class-name="rowClassName"
				height="740"
				border
				keep-source
				ref="xTable1"
				:export-config="{}"
				resizable
				show-overflow
				:data="tableData"
				:edit-config="{ trigger: 'manual', mode: 'row',icon: 'false' }"
				:edit-rules="validRules"
				@checkbox-all="selectAllChangeEvent1"
				@checkbox-change="selectChangeEvent1"
				show-footer
				:footer-method="footerMethod"
			>
				<vxe-column align="center" type="checkbox" width="60" fixed="left"></vxe-column>
				<vxe-column align="center" type="seq" title="序号" width="60"></vxe-column>
				<!-- <vxe-column field="id" title="序号" width="80" :edit-render="{ name: 'input', attrs: { type: 'text' } }"></vxe-column> -->

				<vxe-column field="bankId" title="银行" :edit-render="{ type: 'default' }">
					<template v-slot:edit="scope">
						<el-select clearable filterable v-model="scope.row.bankId">
							<el-option v-for="item in bankFrom.shoWData" :key="item.id" :label="item.bank" :value="item.id"></el-option>
						</el-select>
					</template>
					<template v-slot="{ row }">{{ getSelectLabel(row.bankId, bankFrom.shoWData) }}</template>
				</vxe-column>

				<!-- <vxe-column field="time" title="时间" width="130" :edit-render="{ name: 'input', attrs: { type: 'text' } }"></vxe-column> -->

				<vxe-column
					field="time"
					title="时间"
					width="105"
					:edit-render="{ name: '$input', props: { type: 'date', placeholder: '请选择日期' } }"
				></vxe-column>
				<!-- <vxe-column field="receiveId" title="到款单位" :edit-render="{ name: 'input', attrs: { type: 'text' } }"></vxe-column> -->

				<vxe-column field="receiveId" title="到款单位" :edit-render="{ type: 'default' }">
					<template v-slot:edit="scope">
						<el-select clearable filterable v-model="scope.row.receiveId">
							<el-option v-for="item in selectFrom.bankData" :key="item.id" :label="item.unitName" :value="item.id"></el-option>
						</el-select>
					</template>
					<template v-slot="{ row }">{{ getSelectLabel_uttls(row.receiveId, selectFrom.bankData) }}</template>
				</vxe-column>

				<vxe-column field="toId" title="去款单位" :edit-render="{ type: 'default' }">
					<template v-slot:edit="scope">
						<el-select clearable filterable v-model="scope.row.toId">
							<el-option v-for="item in selectFrom.debitUnit" :key="item.id" :label="item.unitName" :value="item.id"></el-option>
						</el-select>
					</template>
					<template v-slot="{ row }">{{ getSelectLabel_uttls(row.toId, selectFrom.debitUnit) }}</template>
				</vxe-column>

				<!-- <vxe-column field="toId" title="去款单位" :edit-render="{ name: 'input', attrs: { type: 'text' } }"></vxe-column> -->

				<vxe-column field="purpose" width="130" title="用途" :edit-render="{ name: 'input', attrs: { type: 'text' } }"></vxe-column>

				<vxe-column field="contractId" title="项目" width="130" :edit-render="{ type: 'default' }">
					<template v-slot:edit="scope">
						<el-select clearable filterable v-model="scope.row.contractId">
							<el-option v-for="item in selectFrom.contractData" :key="item.id" :label="item.contractName" :value="item.id"></el-option>
						</el-select>
					</template>
					<template v-slot="{ row }">{{ getSelectLabel_contractName(row.contractId, selectFrom.contractData) }}</template>
				</vxe-column>

				<!-- <vxe-column field="contractId" title="项目" :edit-render="{ name: 'input', attrs: { type: 'text' } }"></vxe-column> -->

				<!--  -->
				<!-- <vxe-colgroup title="票据金额">
					<vxe-column field="ticketDebit" width="130" title="借方" :edit-render="{ type: 'default' }">
						<template v-slot:edit="scope">
							<el-input v-model="scope.row.ticketDebit" @change="change_ticket(scope.row)"></el-input>
						</template>
						<template v-slot="{ row }">{{ transitionNumber(row.ticketDebit) }}</template>
					</vxe-column>

					<vxe-column field="ticketLender" width="130" title="贷方" :edit-render="{ type: 'default' }">
						<template v-slot:edit="scope">
							<el-input v-model="scope.row.ticketLender" @change="change_ticket(scope.row)"></el-input>
						</template>
						<template v-slot="{ row }">{{ transitionNumber(row.ticketLender) }}</template>
					</vxe-column>

					<vxe-column field="ticketBalance" width="130" title="余额" :edit-render="{ type: 'default' }">
						<template v-slot:edit="scope">
							<el-input v-model="scope.row.ticketBalance"></el-input>
						</template>
						<template v-slot="{ row }">{{ transitionNumber(row.ticketBalance) }}</template>
					</vxe-column>
				</vxe-colgroup> -->

				<vxe-colgroup title="银行存款">
					<vxe-column field="bankDebit" width="100" title="借方" :edit-render="{ type: 'default' }">
						<template v-slot:edit="scope">
							<el-input v-model="scope.row.bankDebit" @change="change_selValue_bb(scope.row)"></el-input>
						</template>
						<template v-slot="{ row }">{{ transitionNumber(row.bankDebit) }}</template>
					</vxe-column>
					<vxe-column field="bankLender" width="100" title="贷方" :edit-render="{ type: 'default' }">
						<template v-slot:edit="scope">
							<el-input v-model="scope.row.bankLender" @change="change_selValue_bb(scope.row)"></el-input>
						</template>
						<template v-slot="{ row }">{{ transitionNumber(row.bankLender) }}</template>
					</vxe-column>

					<vxe-column field="bankBalance" width="100" title="余额" :edit-render="{ type: 'default' }">
						<template v-slot:edit="scope">
							<el-input v-model="scope.row.bankBalance"></el-input>
						</template>
						<template v-slot="{ row }">{{ transitionNumber(row.bankBalance) }}</template>
					</vxe-column>
				</vxe-colgroup>

				<vxe-column field="remarks" width="100" title="备注" :edit-render="{ name: 'input', attrs: { type: 'text' } }"></vxe-column>

				<!-- <vxe-column field="pictureUrl" width="130" title="图片" :edit-render="{ name: '$select', options: selectFrom.typeArry }"></vxe-column> -->

				<vxe-column title="操作" fixed="right" width="100">
					<template #default="{ row }">
						<vxe-button status="primary" @click="openFileBtn(row)">文件列表</vxe-button>
					</template>
				</vxe-column>
			</vxe-table>
		</el-card>
		<!-- 弹窗 -->
		<vxe-modal v-model="bankFrom.isshow" title="银行数据" width="600" height="420" show-zoom resize remember>
			<template #default>
				<vxe-toolbar perfect>
					<template #buttons>
						<vxe-button icon="fa fa-plus" status="perfect" content="新增" @click="addbankShow"></vxe-button>
						<vxe-button icon="fa fa-trash-o" status="perfect" content="删除" @click="deleteTable_show"></vxe-button>
					</template>
				</vxe-toolbar>
				<vxe-table
					border
					:height="300"
					show-overflow
					ref="xTableShow"
					:data="bankFrom.shoWData"
					:edit-config="{ trigger: 'click', mode: 'row', showStatus: true }"
					@checkbox-all="selectAllChangeEvent1_show"
					@checkbox-change="selectChangeEvent1_show"
					@edit-closed="editClosedEvent_show"
				>
					<vxe-column type="checkbox" width="60" align="center"></vxe-column>
					<vxe-column type="seq" width="60" align="center"></vxe-column>
					<vxe-column field="bank" title="银行名称" :edit-render="{ name: 'input' }"></vxe-column>
					<vxe-column field="ticketBalance" title="票据余额" :edit-render="{ name: 'input' }"></vxe-column>
					<vxe-column field="bankBalance" title="存款余额" :edit-render="{ name: 'input' }"></vxe-column>
				</vxe-table>
			</template>
		</vxe-modal>

		<!-- 新增弹窗 -->
		<vxe-modal v-model="isaddressBook" title="添加通讯录" width="800" height="400" show-zoom resize remember>
			<template #default>
				<vxe-form :data="ressBookFrom" :rules="validRules" title-align="right" title-width="110">
					<vxe-form-item
						title="单位名称"
						field="unitName"
						span="12"
						:item-render="{ name: 'input', attrs: { placeholder: '单位名称' } }"
					></vxe-form-item>

					<vxe-form-item
						title="纳税人识别号"
						field="taxpayerNum"
						span="12"
						:item-render="{ name: 'input', attrs: { placeholder: '纳税人识别号' } }"
					></vxe-form-item>

					<vxe-form-item
						title="地址电话"
						field="addressPhone"
						span="12"
						:item-render="{ name: 'input', attrs: { placeholder: '地址电话' } }"
					></vxe-form-item>

					<vxe-form-item
						title="联系人"
						field="contactPerson"
						span="12"
						:item-render="{ name: 'input', attrs: { placeholder: '联系人' } }"
					></vxe-form-item>

					<vxe-form-item
						title="联系电话1"
						field="phone1"
						span="12"
						:item-render="{ name: 'input', attrs: { placeholder: '联系电话1' } }"
					></vxe-form-item>

					<vxe-form-item
						title="联系电话2"
						field="phone2"
						span="12"
						:item-render="{ name: 'input', attrs: { placeholder: '联系电话2' } }"
					></vxe-form-item>

					<vxe-form-item title="QQ号" field="qq" span="12" :item-render="{ name: 'input', attrs: { placeholder: 'QQ号' } }"></vxe-form-item>

					<vxe-form-item title="联系地址" field="addr" span="12" :item-render="{ name: 'input', attrs: { placeholder: '联系地址' } }"></vxe-form-item>

					<!-- <vxe-form-item title="单位类型" field="type" span="12" :item-render="{ name: 'input', attrs: { placeholder: '单位类型' } }"></vxe-form-item> -->

					<vxe-form-item title="单位类型" field="type" span="12" :item-render="{}" title-overflow>
						<template #default="params">
							<vxe-select v-model="params.data.type" placeholder="单位类型" clearable>
								<vxe-option value="1" label="供应商"></vxe-option>
								<vxe-option value="2" label="客户"></vxe-option>
								<vxe-option value="3" label="公司员工"></vxe-option>
								<vxe-option value="4" label="合作伙伴"></vxe-option>
							</vxe-select>
						</template>
					</vxe-form-item>

					<vxe-form-item align="center" span="24">
						<template #default>
							<vxe-button type="submit" status="primary" @click="showSubmit">保 存</vxe-button>
							<vxe-button @click="isaddressBook = false">取消</vxe-button>
						</template>
					</vxe-form-item>
				</vxe-form>
			</template>
		</vxe-modal>

		<!-- 文件列表 -->
		<vxe-modal v-model="showFileList.isShow" title="文件列表" width="600" height="420" show-zoom resize remember>
			<template #default>
				<vxe-toolbar perfect>
					<template #buttons>
						<vxe-button icon="fa fa-plus" status="perfect" content="上传文件" @click="uploadingbutton()"></vxe-button>
						<!-- <vxe-button   status="primary" @click="uploadingbutton(row)">上传文件</vxe-button> -->
					</template>
				</vxe-toolbar>
				<vxe-table border :height="300" show-overflow ref="xTableShow" :data="showFileList.fileList">
					<vxe-column type="seq" width="60" align="center"></vxe-column>
					<vxe-column field="name" title="文件列表"></vxe-column>
					<vxe-column title="操作" fixed="right" align="center" width="230">
						<template #default="{ row }">
							<vxe-button status="primary" @click="download(row)">下载文件</vxe-button>
							<vxe-button @click="deleteFile(row)">删除文件</vxe-button>
						</template>
					</vxe-column>
				</vxe-table>
			</template>
		</vxe-modal>
	</div>
</template>

<script lang="ts">
import { toRefs, reactive, ref, toRaw, onMounted, nextTick } from 'vue';

import { ElMessage, ElMessageBox } from 'element-plus';
import { axios_SelList, axios_contractselListTop, axios_fileupload, axiosGetFileList, axiosGetFiledel } from '/@/api/basicsUrl/index'; //通讯录接口
import {
	axios_bankselList,
	axios_bankdel,
	axios_bankadd,
	axios_bankup,
	axios_cashierselList,
	axios_cashierdel,
	axios_cashierup,
	axios_cashieradd,
	axios_cashierselValue_tb, //计算商票台账余额
	axios_cashierserselValue_bb, //计算银行存款余额
} from '/@/api/addressBook/index';
// 不重复id
import { GenNonDuplicateID } from '/@/utils/formatTime';
import { VXETable, VxeTablePropTypes } from 'vxe-table';
import { axios_contactsAdd } from '/@/api/addressBook/index';

import { axios_excelcashier } from '/@/api/basicsUrl/index';
import { transitionNumber } from '/@/utils/transitionNumber';

export default {
	name: 'PaymentDetail',
	setup() {
		const xTable1 = ref({} as VxeTableInstance);
		const xToolbar = ref({} as VxeToolbarInstance);

		// 打印样式
		// 打印样式
		const printStyle = `
            .title {
              text-align: center;
            }
            .my-list-row {
              display: inline-block;
              width: 100%;
            }
            .my-list-col {
              float: left;
              width: 33.33%;
              height: 28px;
              line-height: 28px;
            }
            .my-top,
            .my-bottom {
              font-size: 12px;
            }
            .my-top {
              margin-bottom: 5px;
            }
            .my-bottom {
              margin-top: 30px;
              text-align: right;
            }
            `;

		// 打印顶部内容模板
		const topHtml = `
            <h1 class="title">出货单据</h1>
            <div class="my-top">
              <div class="my-list-row">
                <div class="my-list-col">商品名称： </div>
                <div class="my-list-col">发货单号：X2665847132654</div>
                <div class="my-list-col">发货日期：2020-09-20</div>
              </div>
              <div class="my-list-row">
                <div class="my-list-col">收货姓名： </div>
                <div class="my-list-col">收货地址：火星第七区18号001</div>
                <div class="my-list-col">联系电话：10086</div>
              </div>
            </div>
            `;

		// 打印底部内容模板
		const bottomHtml = `
            <div class="my-bottom">
              <div class="my-list-row">
                <div class="my-list-col"></div>
                <div class="my-list-col">创建人： </div>
                <div class="my-list-col">创建日期：2020-09-20</div>
              </div>
            </div>
            `;

		/**
		 * @Author: lilin_:）
		 * @name: 默认空白数组
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		let defaultBlankData = [
			{
				iswebAdd: true,
				webid: GenNonDuplicateID(),
				unitName: '',
				taxpayerNum: '',
				addressPhone: '',
				accountBank: '',
				bankAccount: '',
				bankName: '',
				contactPerson: '',
				phone1: '',
				phone2: '',
				qq: '',
				addr: '',
				bankDebit: '',
				bankLender: '',
				bankBalance: '',
				type: 2,
			},
		];

		let defaultBlankDataShow = [
			{
				iswebAdd: true,
				webid: GenNonDuplicateID(),
				type: '', //银行名字
			},
		];

		const validRules = ref({
			bankId: [{ required: true, message: '银行必选' }],
			time: [{ required: true, message: '时间必选' }],
			unitName: [{ required: true, message: '单位名称必填' }],
			taxpayerNum: [{ required: true, message: '纳税人识别号必填' }],
			type: [{ required: true, message: '单位类型必填' }],
			contactPerson: [{ required: true, message: '联系人必填' }],

			// receiveId: [{ required: true, message: '到款单位必选' }],
			// contractId: [{ required: true, message: '项目必选' }],
		} as VxeTablePropTypes.EditRules);

		const state: any = reactive({
			showSun: {
				v1: 0,
				v2: 0,
			}, //显示的合计，
			addList: [], //前端加的数据
			responseData: [], //后端返回的数据

			isaddressBook: false, //通讯路弹窗
			// typeArry: [
			// 	{ label: '供应商', value: '1' },
			// 	{ label: '客户', value: '2' },
			// 	{ label: '公司员工', value: '3' },
			// 	{ label: '合作伙伴', value: '4' },
			// ],
			// 文件列表
			showFileList: {
				isShow: false, //是否打开
				fileList: [], // 文件集合
				sasveFileItem: '', //存储数据对象
			},
			//通讯录弹窗
			ressBookFrom: {
				unitName: '', //单位名称
				taxpayerNum: '', //纳税人识别号
				addressPhone: '', //地址电话
				// accountBank: '',//联系人
				// bankAccount: '',
				// bankName: '',
				contactPerson: '', //联系人
				phone1: '',
				phone2: '',
				qq: '',
				addr: '', //联系地址
				type: '', //单位类型
			},

			selectFrom: {
				on: 0, //默认是0，1是点击
				time1: '', //时间
				time2: '', //结束时间
				purpose: '', //用途
				remarks: '', //备注

				bankId: '', //银行id
				bankData: [], //银行数据
				debitUnit: [], //取款单位

				receiveId: '', //到款单位id
				toId: '', //去款单位id,
				contractId: '', //项目id
				contractData: [], //项目数据

				//
				contactPerson: '', //联系人
				type: '', //单位类型1供应商2客户3公司员工
				typeArry: [
					{ label: '供应商', value: '1' },
					{ label: '客户', value: '2' },
					{ label: '公司员工', value: '3' },
				], //单位类型1供应商2客户3公司员工
				unitsData: [], //单位搜索的数据和联系人一样
			},
			bankFrom: {
				isshow: false, //弹窗控制
				shoWData: [], //表格数据
				selectData: [], //多选的数据
			},
			tableData: [], //表格数据
			selectData: [], //选择的数组
		});

		// 获取银行数据
		let getBankData = async () => {
			let { code, obj } = await axios_bankselList();
			if (code == 200) {
				state.bankFrom.shoWData = obj;
				// state.bankFrom.isshow = true;
			}
		};

		// 银行弹窗
		const getBankData_button = async () => {
			let { code, obj } = await axios_bankselList();
			if (code == 200) {
				state.bankFrom.shoWData = obj;
				state.bankFrom.isshow = true;
			}
			// console.log(code, obj, '1111111111111111111111');
		};

		// 银行数据新增
		const addbankShow = () => {
			let addArry = defaultBlankDataShow.map((item: any) => {
				return {
					...item,
					...{
						webid: GenNonDuplicateID(),
					},
				};
			});
			state.bankFrom.shoWData = JSON.parse(JSON.stringify([...state.bankFrom.shoWData, ...addArry]));
			// console.log(toRaw(state.tableData), '11111111111');
			ElMessage.success({
				message: '新增1行空白栏',
				type: 'success',
			});
		};

		const selectAllChangeEvent1: VxeTableEvents.CheckboxAll = ({ checked, records }: any) => {
			console.log(checked ? '所有勾选事件' : '所有取消事件', records);
			state.selectData = records;
		};

		const selectChangeEvent1: VxeTableEvents.CheckboxChange = ({ checked, records }: any) => {
			// 重置所有高亮
			state.tableData.forEach((item2: any) => {
				item2.hghligHt = false;
			});
			state.selectData = records;
			console.log(checked ? '勾选事件' : '取消事件', records);
			state.selectData.forEach((item: any) => {
				if (item.iswebAdd) {
					// 前端的数据
					state.tableData.forEach((item2: any) => {
						if (item.webid == item2.webid) {
							item2.hghligHt = true;
						}
					});
				} else {
					state.tableData.forEach((item2: any) => {
						if (item.id == item2.id) {
							item2.hghligHt = true;
						}
					});
				}
			});
		};

		const selectAllChangeEvent1_show: VxeTableEvents.CheckboxAll = ({ checked, records }: any) => {
			console.log(checked ? '所有勾选事件' : '所有取消事件', records);
			state.bankFrom.selectData = records;
		};

		const selectChangeEvent1_show: VxeTableEvents.CheckboxChange = ({ checked, records }: any) => {
			state.bankFrom.selectData = records;
			console.log(checked ? '勾选事件' : '取消事件', records);
		};

		/**
		 * @Author: lilin_:）
		 * @name: 获取通讯录（ 去款单位）
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		const getProjectName = async () => {
			let resData: any = await axios_SelList({ type: '' });
			state.selectFrom.bankData = resData.obj;
			// console.log(toRaw(resData.obj), '我是列表数据');
		};
		// 获取到款单位
		const getDebitUnit = async () => {
			let resData: any = await axios_SelList({ type: '' });
			state.selectFrom.debitUnit = resData.obj;
			// console.log(toRaw(resData.obj), '我是列表数据');
		};

		// 查询
		const searchEvent: VxeFormEvents.Submit = async () => {
			// VXETable.modal.message({ content: '查询事件', status: 'info' });
			state.selectFrom.on = 1;
			await getArryList();
		};

		// 查询所有项目
		const getAllProject = () => {
			axios_contractselListTop().then((res) => {
				state.selectFrom.contractData = res.obj;
				// console.log(res, '查询所有项目');
			});
		};

		/**
		 * @Author: lilin_:）
		 * @name: 重置搜索表单
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		const resetEvent: VxeFormEvents.Reset = async () => {
			state.selectFrom.on = 0;
			state.selectFrom.time1 = ''; //清空时间
			state.selectFrom.time2 = ''; //清空时间
			state.selectFrom.purpose = ''; //清空时间
			state.selectFrom.remarks = ''; //清空时间

			state.selectFrom.bankId = ''; //清空时间
			state.selectFrom.receiveId = ''; //单位名称
			state.selectFrom.toId = ''; //项目名称
			state.selectFrom.contractId = ''; //项目名称
			await getArryList();
			// VXETable.modal.message({ content: '重置事件', status: 'info' });
		};

		/**
		 * @Author: lilin_:）
		 * @name: 获取列表
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		const getArryList = () => {
			// let subTme = ''; //判断是否有时间
			// if (state.selectFrom.time) {
			// 	subTme = `${state.selectFrom.time[0]}_${state.selectFrom.time[1]}`;
			// }
			let data = {
				on: state.selectFrom.on,
				purpose: state.selectFrom.purpose,
				remarks: state.selectFrom.remarks,
				time1: state.selectFrom.time1,
				time2: state.selectFrom.time2,
				bankId: state.selectFrom.bankId,
				receiveId: state.selectFrom.receiveId,
				toId: state.selectFrom.toId,
				contractId: state.selectFrom.contractId,
			};

			// console.log(data, '我是提交的数据');
			axios_cashierselList(data).then((res: any) => {
				if (res.code == 200) {
					// 重置数据
					state.addList = [];
					// 添加20条数据
					for (let index = 0; index < 20; index++) {
						state.addList.push(
							defaultBlankData.map((item: any) => {
								return {
									...item,
									...{
										webid: GenNonDuplicateID(),
									},
								};
							})[0]
						);
					}
					state.responseData = res.obj;
					state.tableData = [...state.responseData, ...state.addList];
					state.selectData = [];
					state.showSun = res.data;
				}
			});
		};
		// 添加单位的弹窗---------------------------
		// 添加通讯录
		const addUnit = () => {
			// 清空数据
			state.ressBookFrom.unitName = '';
			state.ressBookFrom.taxpayerNum = '';
			state.ressBookFrom.addressPhone = '';
			state.ressBookFrom.contactPerson = '';
			state.ressBookFrom.phone1 = '';
			state.ressBookFrom.phone2 = '';
			state.ressBookFrom.qq = '';
			state.ressBookFrom.addr = '';
			state.ressBookFrom.type = '';
			// 获取单位类型
			state.isaddressBook = true;
		};

		onMounted(() => {
			getArryList(); //获取列表

			getAllProject(); //获取项目
			getProjectName(); //
			getDebitUnit(); //取款单位

			getBankData(); //获取银行数据

			// let a = GenNonDuplicateID()
			// console.log(a)
		});

		//实时更新
		const editClosedEvent: VxeTableEvents.EditClosed = ({ row, column }) => {
			// let getRow: any = row;

			if (state.selectData.length == 1) {
				let row = state.selectData[0];

				if (row.iswebAdd) {
					axios_cashieradd(row).then((res) => {
						if (res.code == 200) {
							state.selectFrom.on = 1;
							getArryList(); //列表
							VXETable.modal.message({ content: '新增成功!', status: 'success' });
						}
					});
				} else {
					axios_cashierup(row).then((res) => {
						if (res.code == 200) {
							state.selectFrom.on = 1;
							getArryList(); //列表
							VXETable.modal.message({ content: '编辑成功！', status: 'success' });
						}
					});
				}
			} else if (state.selectData.length == 0) {
				VXETable.modal.message({ content: '您还没有选中行', status: 'warning' });
			} else {
				VXETable.modal.message({ content: '只能选中一行编辑', status: 'warning' });
			}

			// const $table = xTable1.value;
			// const field = column.property;
			// const cellValue = row[field];
			// 判断单元格值是否被修改;
			// if ($table.isUpdateByRow(row, field)) {
			// 	setTimeout(() => {
			// 		VXETable.modal.message({
			// 			content: `局部保存成功！ ${field}=${cellValue}`,
			// 			status: 'success',
			// 		});
			// 		// 局部更新单元格为已保存状态
			// 		$table.reloadRow(row, null, field);
			// 	}, 300);
			// }
		};

		//实时更新弹窗
		const editClosedEvent_show: VxeTableEvents.EditClosed = ({ row, column }) => {
			// let getRow: any = row;
			if (row.iswebAdd) {
				// 走保存接口
				axios_bankadd(row).then((res) => {
					// console.log(res, '是否啊添加');
					if (res.code == 200) {
						getBankData_button();
					}
				});
			} else {
				axios_bankup(row).then((res) => {
					if (res.code == 200) {
						getBankData_button();
					}
				});
			}
		};
		/**
		 * @Author: lilin_:）
		 * @name: 关联表格
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		nextTick(() => {
			// 将表格和工具栏进行关联
			const $table = xTable1.value;
			const $toolbar = xToolbar.value;
			$table.connect($toolbar);
		});

		/**
		 * @Author: lilin_:）
		 * @name: 新增空白行
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		const addDefaultBlank = () => {
			let addArry = defaultBlankData.map((item: any) => {
				return {
					...item,
					...{
						webid: GenNonDuplicateID(),
						hghligHt: true,
					},
				};
			});
			let row = addArry[0];
			// let showArry = JSON.parse(JSON.stringify(state.tableData)); // state.responseData.push(row);
			state.addList.unshift(row);
			state.tableData = [...state.responseData, ...state.addList];

			const $table = xTable1.value;
			$table.clearCheckboxRow();
			$table.toggleCheckboxRow(state.addList[0]); //默认选中第一行
			state.selectData = [state.addList[0]]; //拿到选择数据
			$table.setActiveRow(row);
			ElMessage.success({
				message: '新增1行空白栏',
				type: 'success',
			});

			// 计算滚动高度
			let heightpx = state.responseData.length * 40;
			setTimeout(() => {
				document.getElementsByClassName('vxe-table--body-wrapper')[0].scrollTo(0, heightpx);
			}, 100);
		};

		/**
		 * @Author: lilin_:）
		 * @name: 删除数据
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		const deleteTable: any = async () => {
			let webAddArry: any = [];
			let reeData: any = [];
			state.selectData.forEach((item: any) => {
				if (item.iswebAdd == true) {
					webAddArry.push(item);
				} else {
					reeData.push(item);
				}
			});
			// 判断前端数据是否有值
			let webDelet = () => {
				if (webAddArry.length != 0) {
					// 前端删除
					state.addList = state.addList.filter((item: any) => {
						return !webAddArry.find((_item: any) => _item.webid === item.webid);
					});
					state.selectData = [];
					state.tableData = [...state.responseData, ...state.addList];
				}
			};
			let resDelet = async () => {
				if (reeData.length != 0) {
					let { code }: object = await axios_cashierdel(
						reeData.map((item: any) => {
							return item.id;
						})
					);
					if (code == 200) {
						state.selectFrom.on = 1;
						await getArryList();
					}
				}
			};
			await resDelet();
			await webDelet();
		};

		// 弹窗删除
		const deleteTable_show: any = async () => {
			let webAddArry: any = [];
			let reeData: any = [];
			state.bankFrom.selectData.forEach((item: any) => {
				if (item.iswebAdd == true) {
					webAddArry.push(item);
				} else {
					reeData.push(item);
				}
			});
			// 判断前端数据是否有值
			let webDelet = () => {
				if (webAddArry.length != 0) {
					// 前端删除
					state.bankFrom.shoWData = state.bankFrom.shoWData.filter((item: any) => {
						return !webAddArry.find((_item: any) => _item.webid === item.webid);
					});
				}
			};

			let resDelet = async () => {
				if (reeData.length != 0) {
					let { code }: object = await axios_bankdel(
						reeData.map((item: any) => {
							return item.id;
						})
					);
					// console.log(code, '11111111');
					if (code == 200) {
						let { code, obj } = await axios_bankselList();
						if (code == 200) {
							state.bankFrom.shoWData = obj;
						}
					}
				}
			};
			await resDelet();
			await webDelet();
		};

		/**
		 * @Author: lilin_:）
		 * @name: 高级导出功能
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		const funnelEvent = () => {
			const $table = xTable1.value;
			$table.openExport();
		};

		/**
		 * @Author: lilin_:）
		 * @name: 打印表格
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		const printTab = () => {
			const $table = xTable1.value;
			$table.print({
				sheetName: '出纳明细',
				style: printStyle, //自定义样式
				columns: [
					{ field: 'id' },
					{ field: 'bankId' },
					{ field: 'time' },
					{ field: 'receiveId' },

					{ field: 'toId' },

					{ field: 'purpose' },

					{ field: 'contractId' },
					{ field: 'ticketDebit' },
					{ field: 'ticketLender' },

					{ field: 'ticketBalance' },

					{ field: 'bankDebit' },
					{ field: 'bankLender' },
					{ field: 'bankBalance' },

					{ field: 'remarks' },
				],
				beforePrintMethod: ({ content }) => {
					// 拦截打印之前，返回自定义的 html 内容
					// return topHtml + content + bottomHtml;
					return content;
				},
			});
		};

		// 展示内容下拉搜索
		const getSelectLabel = (value, list) => {
			let item = list.find((item) => item.id == value);
			return item ? item.bank : null;
		};

		// 回显单位
		const getSelectLabel_uttls = (value, list) => {
			let item = list.find((item) => item.id == value);
			return item ? item.unitName : null;
		};
		// 回显contractName 项目
		const getSelectLabel_contractName = (value, list) => {
			let item = list.find((item) => item.id == value);
			return item ? item.contractName : null;
		};
		// 计算计算商票台账余额
		let change_ticket = (item: any) => {
			// if (item.ticketDebit != '' && item.ticketLender != '') {}

			console.log(toRaw(item), '111111111');

			axios_cashierselValue_tb({
				bankId: item.bankId,
				time: item.time,
				id: item.id,
				toUnit: item.toId,
				contractId: item.contractId,
				debit: item.ticketDebit,
				lender: item.ticketLender,
			}).then((res) => {
				if (res.code == 200) {
					if (item.iswebAdd) {
						// 前端的数据
						state.tableData.forEach((item_data, itemdata_index) => {
							if (item_data.webid == item.webid) {
								// console.log(itemdata_index,'itemdata_index')
								item_data.ticketBalance = res.data.balance;
							}
						});
					} else {
						state.tableData.forEach((item_data, itemdata_index) => {
							if (item_data.id == item.id) {
								// console.log(itemdata_index,'itemdata_index')
								item_data.ticketBalance = res.data.balance;
							}
						});
					}
					// console.log(res, '111111111111111111111111');
				}
			});
		};

		// 计算计算银行存款余额

		let change_selValue_bb = (item: any) => {
			console.log(toRaw(item), '111111111');
			// if (item.bankDebit != '' && item.bankLender != '') {}
			axios_cashierserselValue_bb({
				bankId: item.bankId,
				time: item.time,
				id: item.id,
				contractId: item.contractId,
				debit: item.bankDebit,
				lender: item.bankLender,
			}).then((res) => {
				if (res.code == 200) {
					if (item.iswebAdd) {
						// 前端的数据
						state.tableData.forEach((item_data, itemdata_index) => {
							if (item_data.webid == item.webid) {
								// console.log(itemdata_index,'itemdata_index')
								item_data.bankBalance = res.data.balance;
							}
						});
					} else {
						state.tableData.forEach((item_data, itemdata_index) => {
							if (item_data.id == item.id) {
								// console.log(itemdata_index,'itemdata_index')
								item_data.bankBalance = res.data.balance;
							}
						});
					}
					// console.log(res, '111111111111111111111111');
				}
			});
		};

		// 上传文件
		let uploadingbutton = async () => {
			let item = state.showFileList.sasveFileItem;

			try {
				const { files } = await VXETable.readFile({
					multiple: true,
				});
				// 数据表 1出纳表 2合同表 3商票台账
				let params = {
					dataSheet: 1,
					id: item.id,
				};
				let formData = new FormData();
				files.forEach((item: any) => {
					formData.append('files', item);
				});
				axios_fileupload(formData, params).then((res: any) => {
					if (res.code == 200) {
						state.selectFrom.on = 0;
						shuaxingFileListFun();
						VXETable.modal.alert(`共：${files.length} 个文件`);
					}
				});

				// 开始处理数据
			} catch (e) {
				ElMessage.error({
					message: '上传出错啦',
					type: 'error',
				});
			}
		};

		let download = (item: any) => {
			console.log(toRaw(item), '11111111111111111111');

			if (!item.name) {
				ElMessage.error({
					message: '当前没有下载资源',
					type: 'error',
				});
				return;
			}

			let downloadFun = () => {
				let url = `${import.meta.env.VITE_API_URL}/file/download/${item.name}`;
				const x = new XMLHttpRequest();
				x.open('GET', url, true);
				x.responseType = 'blob';
				x.onload = function () {
					const url = window.URL.createObjectURL(x.response);
					const a = document.createElement('a');
					a.href = url;
					a.setAttribute('download', item.name);
					a.click();
				};
				x.send();
			};

			downloadFun();
		};

		// 删除文件
		let deleteFile = (item: any) => {
			console.log(item, '1111');
			// 提示
			ElMessageBox.confirm(`是否删除当前文件名称${item.name}`, '警告', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning',
			})
				.then(() => {
					let resData = {
						name: item.name,
						id: state.showFileList.sasveFileItem.id,
						dataSheet: 1,
					};
					axiosGetFiledel(resData).then((res: any) => {
						// console.log(res, 'async');
						ElMessage({
							type: 'success',
							message: '删除成功',
						});
						shuaxingFileListFun();
					});
				})
				.catch(() => {
					ElMessage({
						type: 'info',
						message: '取消删除',
					});
				});
		};

		// 新增通讯录弹窗
		const showSubmit = () => {
			console.log(toRaw(state.ressBookFrom), '1111111111');
			axios_contactsAdd(state.ressBookFrom).then((res) => {
				// console.log(res, '是否啊添加');
				if (res.code == 200) {
					state.isaddressBook = false;
					getProjectName();
					getDebitUnit();
				}
			});
		};
		// 导入文件
		let uploadingbutton_chula = async (item: any) => {
			console.log(toRaw(item), 'item');

			try {
				const { file } = await VXETable.readFile({
					multiple: true,
				}); // 数据表 1出纳表 2合同表 3商票台账
				// let params = {
				// 	dataSheet: 3,
				// 	id: item.id,
				// };
				console.log(file, 'file');
				let formData = new FormData();
				formData.append('file', file);
				axios_excelcashier(formData).then((res: any) => {
					if (res.code == 200) {
						state.selectFrom.on = 1;
						getArryList(); //列表
						VXETable.modal.alert(`共：1 个文件`);
					}
				}); // 开始处理数据
			} catch (e) {
				ElMessage.error({
					message: '上传出错啦',
					type: 'error',
				});
			}
		};

		//打开文件列表
		const openFileBtn = async (item: any) => {
			state.showFileList.sasveFileItem = item;
			let { code, obj }: any = await axiosGetFileList({ dataSheet: 1, id: item.id });
			if (code == 200) {
				state.showFileList.isShow = true;
				state.showFileList.fileList = obj.map((item: any) => {
					return {
						name: item,
					};
				});
			}
			// 获取数据
		};

		// 刷新文件列表数据
		const shuaxingFileListFun = async () => {
			let { obj }: any = await axiosGetFileList({ dataSheet: 1, id: state.showFileList.sasveFileItem.id });
			state.showFileList.fileList = obj.map((item: any) => {
				return {
					name: item,
				};
			});
		};

		const showAmendFun = () => {
			if (state.selectData.length == 1) {
				let row = state.selectData[0];
				row.hghligHt = true;
				const $table = xTable1.value;
				$table.setActiveRow(row);
			} else if (state.selectData.length == 0) {
				VXETable.modal.message({ content: '您还没有选中行', status: 'warning' });
			} else {
				VXETable.modal.message({ content: '只能选中一行编辑', status: 'warning' });
			}
		};
		// 改变颜色样式
		const rowClassName: VxeTablePropTypes.RowClassName = ({ row }) => {
			// console.log(row, 'rowIndex');
			if (row.hghligHt) {
				return 'row-green';
			}
			return null;
		};

		const footerMethod: VxeTablePropTypes.FooterMethod = ({ columns, data }) => {
			return [
				columns.map((column, columnIndex) => {
					// console.log(columnIndex, '1');
					// if (columnIndex === 5) {
					// 	return `合计`;
					// }
					if (columnIndex === 8) {
						return `${state.showSun.v1}`;
					}
					if (columnIndex === 9) {
						return `${state.showSun.v2}`;
					}
					return '';
				}),
			];
		};

		return {
			validRules,
			showAmendFun,
			uploadingbutton_chula,
			...toRefs(state),
			editClosedEvent, //实时更新
			editClosedEvent_show, //实时更新弹窗
			xToolbar, //关联表格
			xTable1, //表格
			addDefaultBlank, //新增空白行
			addbankShow, //弹窗新增数据
			deleteTable, //删除数据
			deleteTable_show, //弹窗删除

			funnelEvent, //导出数据
			printTab, //打印
			getSelectLabel, //回显下拉
			getSelectLabel_uttls, //回显单位
			getSelectLabel_contractName,
			getBankData_button, //新增银行弹窗按钮
			change_ticket, //切换计算商品余额
			change_selValue_bb, //切换计算银行存款
			uploadingbutton, //上传文件
			download, //下载

			selectAllChangeEvent1,
			selectChangeEvent1,
			selectAllChangeEvent1_show,
			selectChangeEvent1_show,

			searchEvent,
			resetEvent,
			// 新增单位弹窗
			addUnit,
			showSubmit, //保存方法
			deleteFile,
			transitionNumber,
			openFileBtn,
			rowClassName,
			footerMethod,
		};
	},
};
</script>

<style scoped lang="scss">
.mytable-style ::v-deep .vxe-body--row.row-green {
	background-color: #bbb;
	color: #fff;
}
</style>
